//
//  FirstLaunchViewController.m
//  花花时尚
//
//  Created by 霍文轩 on 15/9/8.
//  Copyright (c) 2015年 霍文轩. All rights reserved.
//

#import "FirstLaunchViewController.h"

@interface FirstLaunchViewController () <UIScrollViewDelegate>
@property (nonatomic,retain) UIScrollView * scrollView;
@property (nonatomic,retain) UIPageControl * pageControl;
@end

@implementation FirstLaunchViewController
-(void)dealloc{
    [_pageControl release];
    [_scrollView release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];
    
    [self createViews];
}
-(void)createViews{
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    _scrollView.delegate = self;
    _scrollView.bounces = NO;
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 5, 0);
    _scrollView.pagingEnabled = YES;
    [self.view addSubview:_scrollView];
    for (int i=0 ; i<5; i++) {
        UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width * i, 0, self.view.frame.size.width, self.view.frame.size.height)];
        NSString * imagePath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"firstLunchImage%d.png",i+1] ofType:@""];
        imageView.image = [UIImage imageWithContentsOfFile:imagePath];
        [_scrollView addSubview:imageView];
        [imageView release];
    }
    [_scrollView release];
    
    self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 30, self.view.frame.size.width, 10)];
    _pageControl.currentPage = 0;
    _pageControl.numberOfPages = 5;
    _pageControl.pageIndicatorTintColor = [UIColor darkGrayColor];
    _pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
    [_pageControl addTarget:self action:@selector(pageControlAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:_pageControl];
    [_pageControl release];
    
    UIButton * enterButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 140, 35)];
    enterButton.center = CGPointMake(self.view.frame.size.width * 4 + self.view.frame.size.width / 2, self.view.frame.size.height - 70);
    enterButton.layer.cornerRadius = 5;
    [enterButton setTitle:@"马上开启" forState:UIControlStateNormal];
    [enterButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    enterButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"firstLaunchButton" ofType:@"png"]]];
    [_scrollView addSubview:enterButton];
    [enterButton addTarget:self action:@selector(enterClick) forControlEvents:UIControlEventTouchUpInside];
    [enterButton release];
}
-(void)enterClick{
    [self.delegate enterApp];
}
-(void)pageControlAction:(UIPageControl *)pageControl{
    [_scrollView setContentOffset:CGPointMake(self.view.frame.size.width * pageControl.currentPage, 0) animated:YES];
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    _pageControl.currentPage = scrollView.contentOffset.x / self.view.frame.size.width;
}
@end
